﻿//==================================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 文件名: V_HF_AbnormalTask.cs
// 作 者：代码自动生成
// 日 期：2012-2-21 15:28:52
// 描 述：
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00             
//==================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Text;
using Csla;
using lite;
using Csla.Validation;
using Csla.Data;
using System.Data.SqlClient;
using ZX.DAL;
using OpenExpressApp.ORM;

namespace ZX.CRM.Library
{
	/// <summary>
    /// 
    /// </summary>
	[Serializable]
    [Table(Name="V_HF_AbnormalTask")]
    [ZX.DBModule.Table("V_HF_AbnormalTask","WorkFlowNo")]
	public class V_HF_AbnormalTask: ZX.DBModule.BaseEntity
	{
        #region Business Methods 业务方法
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > WorkFlowNoProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< string >("WorkFlowNo"));
        [DataObjectField(true, true)]
        [Column, PK]
        public string WorkFlowNo
        {
            get { return GetProperty(WorkFlowNoProperty); }
            set { SetProperty(WorkFlowNoProperty, value); }
        }
        
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > WorkFlowInstanceIdProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< string >("WorkFlowInstanceId"));
        [Column]
        public string WorkFlowInstanceId
        {
            get { return GetProperty(WorkFlowInstanceIdProperty); }
            set { SetProperty(WorkFlowInstanceIdProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > WorkFlowIdProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< string >("WorkFlowId"));
        [Column]
        public string WorkFlowId
        {
            get { return GetProperty(WorkFlowIdProperty); }
            set { SetProperty(WorkFlowIdProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > FlowInstanceCaptionProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< string >("FlowInstanceCaption"));
        [Column]
        public string FlowInstanceCaption
        {
            get { return GetProperty(FlowInstanceCaptionProperty); }
            set { SetProperty(FlowInstanceCaptionProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > DescriptionProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< string >("Description"));
        [Column]
        public string Description
        {
            get { return GetProperty(DescriptionProperty); }
            set { SetProperty(DescriptionProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > PriorityProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< string >("Priority"));
        [Column]
        public string Priority
        {
            get { return GetProperty(PriorityProperty); }
            set { SetProperty(PriorityProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > StatusProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< string >("Status"));
        [Column]
        public string Status
        {
            get { return GetProperty(StatusProperty); }
            set { SetProperty(StatusProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< DateTime > StartTimeProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< DateTime >("StartTime"));
        [Column]
        public DateTime StartTime
        {
            get { return GetProperty(StartTimeProperty); }
            set { SetProperty(StartTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< DateTime > EndTimeProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< DateTime >("EndTime"));
        [Column]
        public DateTime EndTime
        {
            get { return GetProperty(EndTimeProperty); }
            set { SetProperty(EndTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< DateTime > SuspendTimeProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< DateTime >("SuspendTime"));
        [Column]
        public DateTime SuspendTime
        {
            get { return GetProperty(SuspendTimeProperty); }
            set { SetProperty(SuspendTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > SuspendStausProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< string >("SuspendStaus"));
        [Column]
        public string SuspendStaus
        {
            get { return GetProperty(SuspendStausProperty); }
            set { SetProperty(SuspendStausProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< int > SuspendTotalSecondsProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< int >("SuspendTotalSeconds"));
        [Column]
        public int SuspendTotalSeconds
        {
            get { return GetProperty(SuspendTotalSecondsProperty); }
            set { SetProperty(SuspendTotalSecondsProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< bool > IsSubWorkFlowProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< bool >("IsSubWorkFlow"));
        [Column]
        public bool IsSubWorkFlow
        {
            get { return GetProperty(IsSubWorkFlowProperty); }
            set { SetProperty(IsSubWorkFlowProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > MainWorkFlowInstanceIdProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< string >("MainWorkFlowInstanceId"));
        [Column]
        public string MainWorkFlowInstanceId
        {
            get { return GetProperty(MainWorkFlowInstanceIdProperty); }
            set { SetProperty(MainWorkFlowInstanceIdProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > MainWorkTaskInstanceIdProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< string >("MainWorkTaskInstanceId"));
        [Column]
        public string MainWorkTaskInstanceId
        {
            get { return GetProperty(MainWorkTaskInstanceIdProperty); }
            set { SetProperty(MainWorkTaskInstanceIdProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > MainWorkTaskIdProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< string >("MainWorkTaskId"));
        [Column]
        public string MainWorkTaskId
        {
            get { return GetProperty(MainWorkTaskIdProperty); }
            set { SetProperty(MainWorkTaskIdProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > MainWorkFlowIdProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< string >("MainWorkFlowId"));
        [Column]
        public string MainWorkFlowId
        {
            get { return GetProperty(MainWorkFlowIdProperty); }
            set { SetProperty(MainWorkFlowIdProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > NowTaskIdProperty = RegisterProperty(typeof(V_HF_AbnormalTask),new PropertyInfo< string >("NowTaskId"));
        [Column]
        public string NowTaskId
        {
            get { return GetProperty(NowTaskIdProperty); }
            set { SetProperty(NowTaskIdProperty, value); }
        }
        #endregion
        
        #region Validation Rules 验证规则
        //将验证规则与业务对象的属性联系在一起
        protected override void AddBusinessRules()
        {
            //AddRule的第一个参数是委托变量，也就是说是方法的变量
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkFlowInstanceId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkFlowInstanceId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkFlowId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkFlowId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "FlowInstanceCaption");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("FlowInstanceCaption", 128));
            ValidationRules.AddRule(CommonRules.StringRequired, "Description");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Description", 512));
            ValidationRules.AddRule(CommonRules.StringRequired, "Priority");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Priority", 1));
            ValidationRules.AddRule(CommonRules.StringRequired, "Status");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Status", 1));
            ValidationRules.AddRule(CommonRules.StringRequired, "SuspendStaus");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("SuspendStaus", 1));
            ValidationRules.AddRule(CommonRules.StringRequired, "MainWorkFlowInstanceId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("MainWorkFlowInstanceId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "MainWorkTaskInstanceId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("MainWorkTaskInstanceId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "MainWorkTaskId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("MainWorkTaskId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "MainWorkFlowId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("MainWorkFlowId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "NowTaskId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("NowTaskId", 50));
            //base.AddBusinessRules();
        }
        #endregion
        
        #region Factory Methods 工厂方法

        public V_HF_AbnormalTask(){}

        public static V_HF_AbnormalTask New()
        {
            return DataPortal.Create< V_HF_AbnormalTask>();
        }
        public static V_HF_AbnormalTask Get(string WorkFlowNo)
        {
            return DataPortal.Fetch< V_HF_AbnormalTask>(new SingleLazyCriteria< V_HF_AbnormalTask, string>(WorkFlowNo, false));
        }
        public static void Delete(string WorkFlowNo )
        {
            DataPortal.Delete(WorkFlowNo);
        }
        
        #endregion
        
        #region Data Access 数据访问
        //由于DataPortal_create中没有对数据库的访问，所有标记了Runlocal特性，使得该方法只需在本地运行即可
        //如果代码中有访问数据库的方法，那么就不要用这个特性，使数据门户可以根据情况将此方法的运行选择在应用服务器还是本地
        [RunLocal()]
        protected override void DataPortal_Create()
        {
            //在此调用CheckRules对所有的属性进行验证规则的检查，这样检查只运行一次。
            ValidationRules.CheckRules();
        }


        //可以看到此方法没有标记任何特性
        //此方法要访问数据库所以不能标记本地，由于她没有任何数据库更新操作所以也无需事务性的保护
        //此方法调用结束后会隐含的调用MarkOld（）方法
        private void DataPortal_Fetch(string WorkFlowNo)
        {
            //通过连接字符串建立SQL连接对象，Using符号代表，范围释放的意思，SqlConnection对象会在此范围后被释放掉
             using (var ctx = ConnectionManager<SqlConnection>.GetManager(ConnectionStringNames))
            {
                IDb db = DbFactory.Instance.GetDb(ctx.Connection);
                IQuery q = db.Query();
                q.Constrain("WorkFlowNo").Equal(WorkFlowNo);
                
                var data = db.Select< V_HF_AbnormalTask>(q)[0];
                LoadProperty(WorkFlowNoProperty, data.WorkFlowNo);
                LoadProperty(WorkFlowInstanceIdProperty, data.WorkFlowInstanceId);
                LoadProperty(WorkFlowIdProperty, data.WorkFlowId);
                LoadProperty(FlowInstanceCaptionProperty, data.FlowInstanceCaption);
                LoadProperty(DescriptionProperty, data.Description);
                LoadProperty(PriorityProperty, data.Priority);
                LoadProperty(StatusProperty, data.Status);
                LoadProperty(StartTimeProperty, data.StartTime);
                LoadProperty(EndTimeProperty, data.EndTime);
                LoadProperty(SuspendTimeProperty, data.SuspendTime);
                LoadProperty(SuspendStausProperty, data.SuspendStaus);
                LoadProperty(SuspendTotalSecondsProperty, data.SuspendTotalSeconds);
                LoadProperty(IsSubWorkFlowProperty, data.IsSubWorkFlow);
                LoadProperty(MainWorkFlowInstanceIdProperty, data.MainWorkFlowInstanceId);
                LoadProperty(MainWorkTaskInstanceIdProperty, data.MainWorkTaskInstanceId);
                LoadProperty(MainWorkTaskIdProperty, data.MainWorkTaskId);
                LoadProperty(MainWorkFlowIdProperty, data.MainWorkFlowId);
                LoadProperty(NowTaskIdProperty, data.NowTaskId);
            }
        }

        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_DeleteSelf()
        {
            //依然是调用下面的方法删除的，只是他此时可以获得自己的Id
            DataPortal_Delete(WorkFlowNoProperty);
        }
        #endregion
	}
}

